package com.pediOnline.persistense;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.pediOnline.entities.User;

@Repository
//@Transactional
public class UserDAO {
	public static final int RESULTS = 20;

	private EntityManager eM;

	public EntityManager getEntityManager() {
		return eM;
	}

	public void setEntityManager(EntityManager eManager) {
		this.eM = eManager;
	}

	@Autowired
	public UserDAO(EntityManagerFactory eMF) {
		setEntityManager(eMF.createEntityManager());
	}

	public void save(User user) {
		getEntityManager().getTransaction().begin();
		getEntityManager().persist(user);
		getEntityManager().getTransaction().commit();
	}

	public void delete(User user) {
		getEntityManager().getTransaction().begin();
		getEntityManager().remove(user);
		getEntityManager().getTransaction().commit();
	}
}